package com.huatai.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huatai.common.util.StringUtil;
import com.huatai.manage.entity.TbModelTypeEntity;
import com.huatai.manage.mapper.TbModelTypeMapper;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.service.TbModelTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 模型类型管理（字典）; 服务实现类
 * </p>
 *
 * @author luoxc
 * @since 2023-03-22
 */
@Service
public class TbModelTypeServiceImpl extends ServiceImpl<TbModelTypeMapper, TbModelTypeEntity> implements TbModelTypeService {

	/**
	 * 分页获取模型类型列表
	 * @param pageQuery
	 * @return
	 */
	@Override
	public Page<TbModelTypeEntity> pageList(PageQuery<TbModelTypeEntity> pageQuery) {
		Page<TbModelTypeEntity> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
		TbModelTypeEntity data = pageQuery.getData();
		LambdaQueryWrapper<TbModelTypeEntity> wrapper = Wrappers.<TbModelTypeEntity>lambdaQuery();
		wrapper.like(StringUtil.isNotBlank(data.getTypeName()), TbModelTypeEntity::getTypeName, data.getTypeName());
		return page(page, wrapper);
	}

	/**
	 * 根据模型类型id获取模型类型信息
	 * @param modelTypeId
	 * @return
	 */
	@Override
	public TbModelTypeEntity getByModelTypeId(String modelTypeId) {
		LambdaQueryWrapper<TbModelTypeEntity> wrapper = Wrappers.<TbModelTypeEntity>lambdaQuery();
		wrapper.eq(TbModelTypeEntity::getModelTypeId, modelTypeId);
		return getOne(wrapper);
	}

	/**
	 * 根据模型类型id集合删除数据
	 * @param modelTypeIds
	 * @return
	 */
	@Override
	public boolean removes(List<String> modelTypeIds) {
		if (modelTypeIds.isEmpty()) return false;
		LambdaQueryWrapper<TbModelTypeEntity> wrapper = Wrappers.<TbModelTypeEntity>lambdaQuery();
		wrapper.in(TbModelTypeEntity::getModelTypeId, modelTypeIds);
		return remove(wrapper);
	}

	/**
	 * 根据模型类型id修改数据
	 * @param tbModelTypeEntity
	 * @return
	 */
	@Override
	public boolean update(TbModelTypeEntity tbModelTypeEntity) {
		LambdaUpdateWrapper<TbModelTypeEntity> wrapper = Wrappers.<TbModelTypeEntity>lambdaUpdate();
		wrapper.eq(TbModelTypeEntity::getModelTypeId, tbModelTypeEntity.getModelTypeId());
		return update(tbModelTypeEntity, wrapper);
	}
}
